from turtle import *
from DebugTrace import DebugTrace

class Drawing:
    def __init__(self,traceLevel=1,scalingFactor=1):
        self.lastZ=0
        self.scaling=scalingFactor
        self.colorR=0
        self.colorG=0
        self.colorB=0

        self.trace = DebugTrace("Draw",traceLevel)
        
        colormode(255)
        pencolor(self.colorR,self.colorG,self.colorB)

        screensize(7000,7000)
        delay(1)
        #setworldcoordinates(0,0,600,600)

    def incrementColor(self):
        self.colorR+=50
        if self.colorR>255:
            self.colorR=0
            self.colorG+=50
            if self.colorG>255:
                self.colorG=0
                self.colorB+=50
                if self.colorB>255:
                    self.colorR=0
                    self.colorG=0
                    self.colorB=0
        self.trace.trace(3, "Pencolor now R:"+str(self.colorR)+" G:"+str(self.colorG)+" B:"+str(self.colorB))
        pencolor(self.colorR,self.colorG,self.colorB)

    def checkZ(self,z):
        if z!=self.lastZ:
            self.trace.trace(2,"Z now "+str(z))
            self.lastZ=z
            self.incrementColor()

    def drawTo(self,x,y,z):
        self.trace.trace(2,"Drawing to X:"+str(x)+" Y:"+str(y)+" Z:"+str(z))
        self.checkZ(z)
        down()
        goto(x*self.scaling,y*self.scaling)

    def moveTo(self,x,y,z):
        self.trace.trace(2,"Moving to X:"+str(x)+" Y:"+str(y)+" Z:"+str(z))
        self.checkZ(z)
        up()
        goto(x*self.scaling,y*self.scaling)
